package com.xdjd.mobile.business.api.friend;

import com.gitee.easyopen.annotation.Api;
import com.gitee.easyopen.annotation.ApiService;
import com.gitee.easyopen.doc.DataType;
import com.gitee.easyopen.doc.annotation.ApiDoc;
import com.gitee.easyopen.doc.annotation.ApiDocField;
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
import com.gitee.easyopen.exception.ApiException;
import com.xdjd.mobile.business.entity.param.BasePageParam;
import com.xdjd.mobile.business.entity.param.clock.BaseClockParam;
import com.xdjd.mobile.business.entity.param.friend.FriendFocusParam;
import com.xdjd.mobile.business.entity.param.friend.FriendNoticeParam;
import com.xdjd.mobile.business.entity.param.friend.FriendSearchParam;
import com.xdjd.mobile.business.entity.result.BasePageResult;
import com.xdjd.mobile.business.entity.vo.FriendListVO;
import com.xdjd.mobile.business.entity.vo.FriendLockInfoVO;
import com.xdjd.mobile.business.entity.vo.FriendSearchVO;
import com.xdjd.mobile.business.entity.vo.LoginUser;
import com.xdjd.mobile.business.service.FriendService;
import com.xdjd.mobile.system.ApiUtil;
import com.xdjd.mobile.system.anotations.ApiAuth;
import org.apache.commons.lang.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;

@ApiService
@ApiDoc("好友")
public class FriendApi {

    @Autowired
    private FriendService friendService ;

    @Api(name = "nologin.friend.search")
    @ApiDocMethod(description = "搜索好友")
    public FriendSearchVO friendSearch(FriendSearchParam param) {
        return friendService.search(param.getSearchInfo());
    }

    @Api(name = "friend.focus")
    @ApiDocMethod(description = "关注好友")
    public void friendFocus(FriendFocusParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        Long currentUserId = currentUser.getId();
        Long memberId = param.getMemberId();
        if (ObjectUtils.equals(currentUserId,memberId)){
            throw new ApiException("您不能关注自己","-1");
        }
        friendService.focus(currentUserId,memberId);

    }

    @Api(name = "friend.notice")
    @ApiDocMethod(description = "通知对方关注")
    public void friendNotice(FriendNoticeParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        friendService.friendNotice(currentUser.getId(),param.getMemberId());

    }

    @Api(name = "friend.list")
    @ApiDocMethod(description = "好友列表", results = {
            @ApiDocField(name = "totalNum", description = "总记录数", example = "100",dataType = DataType.LONG),
            @ApiDocField(name = "infos", description = "数据", elementClass = FriendListVO.class)})
    public BasePageResult<FriendListVO> friendList(BasePageParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return friendService.friendList(currentUser.getId(),param);
    }

    @Api(name = "friend.lock.info")
    @ApiDocMethod(description = "打卡信息")
    public FriendLockInfoVO friendLockInfo(FriendFocusParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        return friendService.friendLockInfo(currentUser.getId(),param.getMemberId());
    }

    @Api(name = "friend.supervise")
    @ApiDocMethod(description = "打卡监督")
    public void friendSupervise(BaseClockParam param) {
        LoginUser currentUser = ApiUtil.getCurrentUser();
        friendService.friendSupervise(currentUser.getId(),param.getClockNo());
    }














}
